Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Add clarification about using destroy with pointers to value types#2112

Closed
JinShil wants to merge 1 commit into
dlang:masterfrom
JinShil:destroy_doc2
Closed

Add clarification about using destroy with pointers to value types#2112
JinShil wants to merge 1 commit into
dlang:masterfrom
JinShil:destroy_doc2

Conversation

@JinShil

@JinShil JinShil commented Feb 25, 2018

Copy link
Copy Markdown
Contributor

@dlang-bot

Copy link
Copy Markdown

Thanks for your pull request, @JinShil!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@JinShil

JinShil commented Feb 25, 2018

Copy link
Copy Markdown
Contributor Author

Or do we need an overload...something like this?

void destroy(T)(T* obj)
{
    destroy(*obj);   
}

@schveiguy schveiguy changed the title Add clariation about using destroy with pointers to value types Add clarification about using destroy with pointers to value types Feb 25, 2018
Comment thread src/object.d Outdated
/********
To destroy a value type through a pointer, the pointer must be dereferenced.
Otherwise `destroy` will only destroy the pointer itself, not the entity being
pointed to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointed to -> referenced

Comment thread src/object.d Outdated
*/
unittest
{
struct S

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static struct

Comment thread src/object.d Outdated
~this() { dtorCount++; }
}

void main()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this out, it's a unit test. Otherwise, the test doesn't actually get run.

Comment thread src/object.d Outdated
Otherwise `destroy` will only destroy the pointer itself, not the entity being
pointed to.
*/
unittest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safe or @system? Not sure which one applies, but it needs to be tagged.

Comment thread src/object.d Outdated
assert(S.dtorCount == 0);

S* s2 = new S();
destroy(*s2); // destroys the struct pointed to by `s2`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenced by

Comment thread src/object.d Outdated
void main()
{
S* s1 = new S();
destroy(s1); // destroys only the pointer `s1`, not what it points to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarify that destroying a pointer simply just sets it to null.

@schveiguy

Copy link
Copy Markdown
Member

Or do we need an overload...something like this?

If we can verify that this isn't going to interfere with other things like recursive destruction, I'd be all for this. It's what people would expect I would think.

@JinShil

JinShil commented Feb 26, 2018

Copy link
Copy Markdown
Contributor Author

Added alternative destroy overload implementation at #2115 for your consideration. Only #2115 or this PR should be pulled; not both.

@PetarKirov PetarKirov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes LGTM, though I wonder if would be better to do the dereferencing automatically (probably by means of another overload).

@JinShil

JinShil commented Feb 27, 2018

Copy link
Copy Markdown
Contributor Author

though I wonder if would be better to do the dereferencing automatically

@ZombineDev see my last comment in this PR. I added such an overload in PR #2115

@JinShil

JinShil commented Feb 28, 2018

Copy link
Copy Markdown
Contributor Author

After the discussion in #2115, it became apparent that there are a few problems with the current implementation of destroy. I will be submitting pull requests to individually address them. See #2115 (comment)

Depending on how that goes, this PR will either not be needed, or will need modification. For now, there's no use for it being in the PR queue consuming resources, until the implementation of destroy is improved.

@JinShil JinShil closed this Feb 28, 2018
@wilzbach

Copy link
Copy Markdown
Contributor

There are no resources consumed and its easy to lose track of work if it's closed, so I strongly suggest keeping this open until it's really not needed anymore. Just set Blocked as title or label and no one will look at it casually.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants